package net.hxz.modules.controller.backEnd;

import net.hxz.modules.controller.BaseController;
import net.hxz.modules.pojo.Banner;
import net.hxz.modules.services.IBannerService;
import net.wy.myBatisPlugin.page.model.PageRowBounds;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("backEnd/banner")
public class BackEndBannerController extends BaseController{
	private final String PATH = "backEnd/modules/banner/";
	
	@Autowired
	private IBannerService bannerService;
	
	/**
	 * 列表页面
	 * @param page
	 * @param map
	 * @return
	 */
	@RequestMapping(value="list")
	public String list(Long typeId, PageRowBounds page, ModelMap map) {
		map.put("canAdd", bannerService.count() >= 5);
		map.put("list", bannerService.list());
		return PATH + "list";
	}
	
	/**
	 * 修改动作
	 * @param page
	 * @param map
	 * @return
	 */
	@RequestMapping(value="modify.json")
	public void list(Banner banner) {
		bannerService.mod(banner);
	}
	
	/**
	 * 添加页面
	 * @param page
	 * @param map
	 * @return
	 */
	@RequestMapping(value="add")
	public String add() {
		return PATH + "add";
	}
	
	/**
	 * 添加动作
	 * @param page
	 * @param map
	 * @return
	 */
	@RequestMapping(value="add.json")
	public void add(Banner banner, ModelMap map) {
		if(bannerService.count() >= 5){
			super.createJSONError(map, "");
			return;
		}
				
		bannerService.add(banner);
	}
	
	/**
	 * 添加动作
	 * @param page
	 * @param map
	 * @return
	 */
	@RequestMapping(value="del.json")
	public void del(Long bannerId, ModelMap map) {	
		bannerService.del(bannerId);
	}
}

